<template>
  <div id="app">
    <web-head></web-head>
    <router-view name='user'></router-view>
    <router-view name='main'></router-view>
  </div>
</template>

<script>
  import webHead from './components/webHead';

  export default {
    name: 'App',
    components: {
      webHead
    },
    watch: {
      "$route": 'checkLogin'
    },
    created() {
      //重新设置store
      // this.checkLogin();
      // this.$store.commit('sync');
    },
    methods: {
      checkLogin() {
        let isLogin = this.getUser;
        console.log('token' + isLogin);
        //检查是否存在session
        if (isLogin == undefined) {
          this.$router.push('/login');
        }
      }
    },
    computed: {
      getUser() {
        return this.$store.state.username
      }
    }
  };
</script>

<style>
  #app {
    font-family: "Avenir", Helvetica, Arial, sans-serif;
    /* -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
    /*color: #2c3e50; *!*/
  }
</style>
